package com.flx.dis.mq.rocket.controller;

import com.flx.common.utils.result.ResultResponse;
import com.flx.dis.mq.rocket.entity.Message;
import com.flx.dis.mq.rocket.service.producer.RocketProducer;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Fenglixiong
 * @Date: 2021/6/28 17:41
 * @Description:
 */
@Api
@Slf4j
@RestController
@RequestMapping("/rocket")
public class RocketMQController {

    @Autowired
    private RocketProducer rocketProducer;

    @PostMapping("/oneSend")
    public ResultResponse oneSend(@RequestBody Message message){
        rocketProducer.oneSend(message);
        return ResultResponse.success("oneSend success!");
    }

    @PostMapping("/synSend")
    public ResultResponse synSend(@RequestBody Message message){
        SendResult sendResult = rocketProducer.synSend(message);
        return ResultResponse.success(sendResult);
    }

    @PostMapping("/asyncSend")
    public ResultResponse asyncSend(@RequestBody Message message){
        rocketProducer.asyncSend(message);
        return ResultResponse.success("asyncSend success!");
    }

}
